import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { ExamRule, ExamResult } from '@/api/exam/types'
import { QuestionOptionTypeEnum } from '@/api/constants'

// 定义 useMockExamStore 保存模拟考试信息
export const useMockExamStore = defineStore(
  'mock_exam_store',
  () => {

    /**
     * 考试规则
     */
    const examRules = ref<ExamRule[]>([
      // 小车科目一无本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'xc',
        driveTypeName: '小车/C1/C2/C3',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 9 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 12 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 11 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 12 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 15 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 7 },
        ],
        itemScore: 1
      },
      // 摩托车科目一无本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'mtc',
        driveTypeName: '摩托车/D/E/F',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 7 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 5 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 7 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 14 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 8 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 1 },
        ],
        itemScore: 2
      },
      // 货车科目一无本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '货车/A2/B2',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 12 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 5 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 7 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 10 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 10 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 18 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 7 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
        ],
        itemScore: 1
      },
      // 客车科目一无本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '客车/A1/A3/B1',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 7 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 12 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 5 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 10 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
        ],
        itemScore: 1
      },
      // 小车科目四出题规则
      {
        examReason: 'AB',
        baseType: 'km4',
        baseTypeName: '科目四',
        isHaveLocateQuestins: false,
        driveType: 'xc',
        driveTypeName: '小车/C1/C2/C3',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Multiple, questionCount: 10 },
        ],
        itemScore: 2
      },
      // 摩托车科目四出题规则
      {
        examReason: 'AB',
        baseType: 'km4',
        baseTypeName: '科目四',
        isHaveLocateQuestins: false,
        driveType: 'mtc',
        driveTypeName: '摩托车/D/E/F',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Multiple, questionCount: 10 },
        ],
        itemScore: 2
      },
      // 轻型牵引车科目四出题规则
      {
        examReason: 'AB',
        baseType: 'km4',
        baseTypeName: '科目四',
        isHaveLocateQuestins: false,
        driveType: 'qxqyc',
        driveTypeName: '摩托车/C6',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Multiple, questionCount: 10 },
        ],
        itemScore: 2
      },
      // 货车科目四出题规则
      {
        examReason: 'AB',
        baseType: 'km4',
        baseTypeName: '科目四',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '货车/A2/B2',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Multiple, questionCount: 10 },
        ],
        itemScore: 2
      },
      // 货车科目四出题规则
      {
        examReason: 'AB',
        baseType: 'km4',
        baseTypeName: '科目四',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '货车/A2/B2',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 20 },
          { questionOptionType: QuestionOptionTypeEnum.Multiple, questionCount: 10 },
        ],
        itemScore: 2
      },
      // 小车科目有本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: true,
        driveType: 'xc',
        driveTypeName: '小车/C1/C2/C3',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 8 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 10 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 10 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 12 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 15 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 15 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },

        ],
        itemScore: 1
      },
      // 摩托车科目一有本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: true,
        driveType: 'mtc',
        driveTypeName: '摩托车/D/E/F',
        examTime: 45,
        examQuestionCount: 50,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 7 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 5 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 7 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 14 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 8 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 1 },
        ],
        itemScore: 2
      },
      // 货车科目一有本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '货车/A2/B2',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 12 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 18 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },

        ],
        itemScore: 1
      },
      // 货车科目一有本地试题出题规则
      {
        examReason: 'AB',
        baseType: 'km1',
        baseTypeName: '科目一',
        isHaveLocateQuestins: false,
        driveType: 'hc',
        driveTypeName: '客车/A1/A3/B1',
        examTime: 45,
        examQuestionCount: 100,
        standard: 90,
        standardName: '90分及格(满分100分)',
        questionSettingRuleName: '根据公安部规定出题规则组卷',
        questionSettingRule: [
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 12 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 6 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Judge, questionCount: 4 },
          { classesCode: '1101', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
          { classesCode: '1102', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1103', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 18 },
          { classesCode: '1104', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1105', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },
          { classesCode: '1107', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 9 },
          { classesCode: 'locate', questionOptionType: QuestionOptionTypeEnum.Single, questionCount: 6 },

        ],
        itemScore: 1
      },
    ])

    /**
     * 考试结果
     */
    const examResults = ref<ExamResult[]>([])

    // 记得 return
    return {
      examRules, examResults
    }
  },
  // TODO: 持久化
  {
    // persist: true,
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
